home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trusted Irix /B 4.0.4
/
Trusted-Irix B-4.0.1.iso
/
dist
/
eoe1.idb
/
usr
/
include
/
sys
/
fs
/
efs_dir.h.z
/
efs_dir.h
Wrap
C/C++ Source or Header
|
1992-04-03
|
6KB
|
167 lines
#ifndef __efs_dir__
#define __efs_dir__
/*
* Long-name directory structure for the efs.
*
* $Source: /src_trees/calypso/att/usr/src/uts/mips/sys/fs/RCS/efs_dir.h,v $
* $Revision: 3.1 $
* $Date: 87/09/11 13:25:39 $
*/
/*
* Directory block size corresponds to basic block (sector) size,
* for atomic writes.
*/
#define EFS_DIRBSHIFT BBSHIFT
#define EFS_DIRBSIZE BBSIZE
#define EFS_DIRBMASK BBMASK
/*
* A dirblk is composed of 3 major components: a header, entry offsets and
* entries. Initially, a dirblock is all zeros, except for the magic number
* and the freeoffset. A entries are allocated, a byte is reserved at
* the beginning of the "space" array for holding the offset to the entry.
* At the end of the "space" array the actual entry is stored. The directory
* is considered full, if a name is going to be added and (1) there is not
* enough room for the dent plus halfword alignment padding plus the the
* byte offset.
*
* The directory management procedures that return an "offset" actually
* return a magic cookie with the following format:
* directory-block-number<23:0>|index-into-offsets<7:0>
*/
/* entry structure */
struct efs_dent {
union {
ulong l;
ushort s[2];
} ud_inum; /* inumber */
unchar d_namelen; /* length of string in d_name */
char d_name[3]; /* name flex array */
};
/*
* Minimum size of a dent is the whole structure, less the 3 bytes for
* the name storage, plus one byte of a one character minimum name.
*/
#define EFS_DENTSIZE (sizeof(struct efs_dent) - 3 + 1)
#define EFS_MAXNAMELEN ((1<<(sizeof(unsigned char)*BITSPERBYTE))-1)
/* dirblk structure */
#define EFS_DIRBLK_HEADERSIZE 4 /* size of header of dirblk */
struct efs_dirblk {
/* begin header */
ushort magic; /* magic number */
unchar firstused; /* offset to first used dent byte */
unchar slots; /* # of offset slots in dirblk */
/* end header */
/* rest is space for efs_dent's */
unchar space[EFS_DIRBSIZE - EFS_DIRBLK_HEADERSIZE];
};
#define EFS_DIRBLK_MAGIC 0xBEEF /* moo */
/* maximum number of entries that can fit in a dirblk */
#define EFS_MAXENTS \
((EFS_DIRBSIZE - EFS_DIRBLK_HEADERSIZE) / \
(EFS_DENTSIZE + sizeof(unchar)))
/*
* Given a cookie or a byte offset into a file, convert it into an offset
* to the beginning of the dirblk containing that offset/cookie.
*/
#define EFS_DBOFF(cookie) \
((cookie) & (~EFS_DIRBMASK & 0x7FFFFFFF))
/* construct a new cookie */
#define EFS_MKCOOKIE(offset, slot) \
(EFS_DBOFF(offset) | (slot))
/* given a cookie, return the slot # */
#define EFS_SLOT(cookie) \
((cookie) & EFS_DIRBMASK)
/* given a real dirblk byte offset, compact it */
#define EFS_COMPACT(off) ((off) >> 1)
/* given a slot, return the offset for it */
#define EFS_SLOTAT(db, slot) \
EFS_REALOFF( (db)->space[slot] )
/* given a slotoffset, return an efs_dent for it */
#define EFS_SLOTOFF_TO_DEP(db, slotoffset) \
((struct efs_dent *) ((char *)(db) + slotoffset))
#define EFS_SET_SLOT(db, slot, compactoffset) \
((db)->space[slot] = (compactoffset))
/* tag for identifying free spots in the directory */
#define EFS_FREESLOT EFS_DIRBMASK
/* given a compacted offset, turn it into a real dirblk byte offset */
#define EFS_REALOFF(coff) \
((coff) << 1)
/*
* Given the "firstused" value, determine offset to first used byte. A value
* of zero in "firstused" means no bytes are used, and that the offset to
* the first used byte is outside the directories space.
*/
#define EFS_DIR_FREEOFF(firstused) \
(((firstused) == 0) ? EFS_DIRBSIZE : EFS_REALOFF(firstused))
/*
* Given a dirblk, compute the size of the free space. The size of the
* is the amount of space prior to the first used byte, minus the
* amount consumed by the dirblk header and the offsets for the dents.
*/
#define EFS_DIR_FREESPACE(db) \
(EFS_DIR_FREEOFF((db)->firstused) - \
(EFS_DIRBLK_HEADERSIZE + sizeof(unchar) * (db)->slots))
/*
* The efs_dentsize macro gives the minimum record length which will hold the
* directory entry pointed at by dep. efs_dentsizebynamelen calculates the
* size of a struct efs_dent excluding the name array, and adds the name
* length. Given a null-terminated string, efs_dentsizebyname computes the
* size of an efs_dent which has that string as its name. The dentsize
* includes the possible padding to enforce halfword alignment. It does
* not include the offset byte.
*/
#define efs_dentsizebynamelen(namelen) \
(EFS_DENTSIZE + (namelen) - 1 + (((namelen) ^ 1) & 1) )
#define efs_dentsize(dep) \
efs_dentsizebynamelen((dep)->d_namelen)
#define efs_dentsizebyname(name) \
efs_dentsizebynamelen(strlen(name))
/*
* Because the efs_dent structure is only 6 bytes long, and some machines
* require longs to be a long boundaries, the following macros are used
* to get at the inumber.
*/
#if defined(mips) || defined(PM2)
#define EFS_INUM_ISZERO(dep) \
(((dep)->ud_inum.s[0] == 0) && ((dep)->ud_inum.s[1] == 0))
#define EFS_SET_INUM(dep, inum) { \
(dep)->ud_inum.s[0] = (inum) >> 16; \
(dep)->ud_inum.s[1] = (inum); \
}
#define EFS_GET_INUM(dep) \
(((dep)->ud_inum.s[0] << 16) + (dep)->ud_inum.s[1])
#endif
#if defined(IP2)
#define EFS_INUM_ISZERO(dep) ((dep)->ud_inum.l == 0)
#define EFS_SET_INUM(dep, inum) ((dep)->ud_inum.l = (inum))
#define EFS_GET_INUM(dep) ((dep)->ud_inum.l)
#endif
/*
* Minimum and maximum directory entry sizes.
*/
#define EFS_MINDENTSIZE efs_dentsizebynamelen(1)
#define EFS_MAXDENTSIZE efs_dentsizebynamelen(EFS_MAXNAMELEN)
#endif /* __efs_dir_ */